package utils
{
	public class Set
	{
		public function Set() { }
		
		public static function member(e:*, s:Array):Boolean {
			return s.indexOf(e) != -1;
		}
		
		public static function subset(a:Array, s:Array):Boolean {
			for each(var e:* in a) {
				if(!member(e, s)) return false;
			}
			return true;
		}
		
		public static function intersects(a:Array, b:Array):Boolean {
			for each(var e:* in a) {
				if(member(e, b)) return true;
			}
			return false;
		}
	
		public static function intersection(a:Array, b:Array):Array {
			return a.filter(isInB);
			
			function isInB(e:*, index:int, array:Array):Boolean {
				return b.indexOf(e) != -1;
			}
		}
		
		// a-b
		public static function subtract(a:Array, b:Array):Array {
			return a.filter(isNotInB);
			
			function isNotInB(e:*, index:int, array:Array):Boolean {
				return b.indexOf(e) == -1;
			}
		}
	}
}